<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资讯详情</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js"></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/jquery-3.2.0.js"></script>
    <script src="src/jquery.gesture.password.js"></script>

    <script type="text/javascript">
        function closeWin() {
            api.closeWin({});
        };
    </script>
</head>
<style>
    html,
    body {
        height: 100%;
        background: rgba(0, 0, 0, 0);
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav pos" id='topbar'>
        <!-- <a class="aui-pull-left aui-btn" onclick="closeWin()"> -->
        <!-- <span class="aui-iconfont aui-icon-left"></span> -->
        </a>
        <div class="aui-title" id="title_head">请设置密码</div>
    </header>

</body>

<script type="text/javascript">
    apiready = function() {
        var patternLock = api.require('patternLock');
        patternLock.addPatternLock({
            viewName: 'main',
            rightColor: '#ffffff',
            drawColor: '#ffffff',
            wrongColor: '#ffffff',
            normalColor: '#ffffff',
            frame: "{{0,150},{" + api.winWidth + "," + api.winHeight + "}}",
            mode: '1',
            rightCode: '0'
        }, function(ret, err) {
            if (ret) {

                if (ret.status == "2") {
                    api.toast({
                        msg: '请重复输入密码！',
                        duration: 2000,
                        location: 'middle'
                    });
                }
                if (ret.status == "3") {
                  api.toast({
                      msg: '重复输入不一致',
                      duration: 2000,
                      location: 'middle'
                  });
                }
                if (ret.status == "4") {
                  api.toast({
                      msg: '密码设置成功！',
                      duration: 2000,
                      location: 'middle'
                  });
                    $api.setStorage('password', ret.code);

                    // showToast();
                    var rett = api.pageParam.rett;
                    var mobileValue = api.pageParam.mobileValue;
                    var userid = rett.user.id;
                    $api.setStorage('userid', userid);
                    $api.setStorage('mobile', mobileValue);


                    var param = api.pageParam.login;
                    if (param == 'registerRedPacket' || param == 'tiyanjin') {

                        sendMsg();
                        // 上页面刷新数据
                        var refreshUser = 'gotoUser();';
                        api.execScript({
                            name: 'home',
                            script: refreshUser,
                        });

                        // 成功后关闭登录页面
                        api.closeToWin({
                            name: 'home'
                        });
                    } else {
                        var param = api.pageParam.login;
                        if (param == 'licai') {
                            // 上页面刷新数据
                            var refreshUser = 'gotoUser();';
                            api.execScript({
                                name: 'home',
                                script: refreshUser,
                            });
                            sendMsg();
                        } else {

                            api.closeToWin({
                                name: 'home'
                            });
                            // api.closeFrame({
                            //     name: 'login'
                            // });
                            var closeLoginFrame = 'closeLoginFrame();';
                            api.execScript({
                                name: 'home',
                                script: closeLoginFrame,
                            });
                            var refreshUser = 'gotoUser();';
                            api.execScript({
                                name: 'home',
                                script: refreshUser,
                            });

                        }


                        //     // 登录成功后 跳转到user页面调用刷新数据方法
                        //     api.setFrameGroupIndex({
                        //         name: 'nav',
                        //         index: 2,
                        //         reload: true,
                        //     });

                        //     // api.closeFrame({
                        //     //     name: 'login'
                        //     // });
                        //     // api.closeWin();
                    }
                }

            } else {
                alert(JSON.stringify(err));
            }
        });

    };

    function showToast() {
        api.toast({
            msg: '登录成功',
            duration: 2000,
            location: 'middle'
        });

    }

    // 登录成功发送刷新请求
    function sendMsg() {
        api.sendEvent({
            name: 'login_success',
            extra: {
                key1: 'value1',
                key2: 'value2'
            }
        });
    }
</script>

</html>
